package com.renbang.action.user;



import javax.servlet.http.HttpServletRequest;

import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.renbang.model.common.AjaxResult;
import com.renbang.model.common.Page;
import com.renbang.model.common.PageData;
import com.renbang.service.datafile.SoilFileServiceImp;

@Controller
@RequestMapping(value = "user/fileSoil")
public class SoilFileAction {
	@Autowired
	SoilFileServiceImp soilFileServiceImp;
	@Autowired
	SqlSessionTemplate sqlSessionTemplate;
	@RequestMapping(value = "/showList")
	public  @ResponseBody AjaxResult showList(HttpServletRequest request,Page page) {
		PageData pd = new PageData(request);
		Integer count = soilFileServiceImp.findTotal(pd);
		return new AjaxResult(AjaxResult.STATUS_OK, page.getCurrpage()+"",null ,soilFileServiceImp.findInPage(pd), count);
	}
	
	@RequestMapping(value = "/del")
	public @ResponseBody AjaxResult del(Integer id) {
		Integer num = soilFileServiceImp.removeById(id);
		return new AjaxResult(AjaxResult.STATUS_OK, null, "成功删除"+num+"条");
	}
	
	//打开新增或修改页面
	@RequestMapping(value = "/editForm")
	public String editForm(Integer id, HttpServletRequest request) {
		PageData pd;
		if (id != null) {
			pd = soilFileServiceImp.findById(id);
			request.setAttribute("obj", pd);
		}
		return "user/file-form";
	}
	@RequestMapping(value = "/addOrModify")
	public  @ResponseBody AjaxResult insertOrUpdata(HttpServletRequest request) {
		PageData pd = new PageData(request);
		if(pd.get("id")!=null){
			soilFileServiceImp.modify(pd);
			return new AjaxResult(AjaxResult.STATUS_OK, null, "修改成功");
	} else {
		 soilFileServiceImp.add(pd);
		 return new AjaxResult(AjaxResult.STATUS_OK, null, "增加成功");
	}
		
	}
	
}
